package com.portme.client.pages;

import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.portme.client.StaticFactory;
import com.portme.shared.LoginInfo;

public class Homepage extends Composite {
	
	private FlowPanel holdingPanel = new FlowPanel();
	private LoginInfo currentLogin;
	
	public Homepage() {
		currentLogin = StaticFactory.getInstance().getCurrentUserLogin();
		initWidget(holdingPanel);
		createWidget();
	}
	
	private void createWidget() {
		if(currentLogin != null) {
			HorizontalPanel headerWidget = new HorizontalPanel();
			headerWidget.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
			
			Label username;
			Anchor login;
			if(currentLogin.isLoggedIn()) {
				login = new Anchor("Logout", currentLogin.getLogoutUrl());
				username = new Label("Welcome "+currentLogin.getUsername());
			} else {
				login = new Anchor("Login", currentLogin.getLoginUrl());
				username = new Label("Have a google account?");
			}
			headerWidget.add(username);
			headerWidget.add(login);
			
			holdingPanel.add(headerWidget);
		}
	}
}
